﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Model;

namespace DAL
{
   public class SignInDAL
    {
        DBHelper db = new DBHelper();
        public List<SignIn> auctions()
        {
            string sqlShow = "select SignInID, SignInName, SignInPwd, SignInState from SignIn";
            List<SignIn> list = null;
            DataTable dt = db.GetData(sqlShow);
            if (dt.Rows.Count > 0)
            {
                list = new List<SignIn>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    SignIn ac = new SignIn();
                    ac.SignInID = Convert.ToInt32(dt.Rows[i]["SignInID"]);
                    ac.SignInName = dt.Rows[i]["SignInName"].ToString();
                    ac.SignInPwd = dt.Rows[i]["SignInPwd"].ToString();
                    ac.SignInState= dt.Rows[i]["SignInState"].ToString();
                    list.Add(ac);
                }
            }
            return list;

        }
        public bool DeleteSin(SignIn si )
        {
            string DeleteSql = $"delete SignIn where SignInID='{si.SignInID}'";
            if (db.SetData(DeleteSql))
            {
                return true;
            }
            return false;
        }
        public bool UpdateSin(SignIn sid)
        {
            string UpdateSql = $"update SignIn set SignInName='{sid.SignInName}',SignInPwd='{sid.SignInPwd}',SignInState='{sid.SignInState}' where SignInID='{sid.SignInID}'";
            if (db.SetData(UpdateSql))
            {
                return true;
            }
            return false;
        }
        public bool InserSin(SignIn sir)
        {
            string sqlInser = $"insert into [dbo].[SignIn](SignInName, SignInPwd, SignInState)values('{sir.SignInName}',{sir.SignInPwd},'{sir.SignInState}')";
            if (db.SetData(sqlInser))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
